<?php 
	class Db_branch extends CI_Model{
		public function __construct(){
			parent::__construct();
		}
		
		public function listAll(){
			if($this->session->userdata("sess_customer_name") != "eshine"){
				$this->db->where("customer_pkid",$this->session->userdata("sess_customer_id"));
			}
			$config['total_rows'] = $this->db->count_all_results("mobile_branch");
			$config['per_page'] = 20;
			$config['full_tag_open'] = '<div class="pages">';
			$config['full_tag_close'] = '<div>';
			$this->pagination->initialize($config);
			$this->db->select("t2.customer_name,t1.pkid,t1.name_en");
			$this->db->from("mobile_branch t1");
			$this->db->join("mobile_customer t2", "t1.customer_pkid=t2.pkid","left");
			if($this->session->userdata("sess_customer_name") != "eshine")
				$this->db->where("t2.pkid",$this->session->userdata("sess_customer_id"));
			$this->db->order_by("t1.pkid", "DESC");
			$res = $this->db->get();
			//==
			$no = $this->uri->segment(3)+1;
			$i = 1;
			$arr = $res->result_array();
			$item = array();
			foreach ($arr as $P){
				$tmp['c_name']						=$P['customer_name'];
				$tmp['b_name']						=$P['name_en'];
				$this->db->where("branch_pkid",$P['pkid']);
				$num = $this->db->count_all_results("mobile_branch_img");
				$tmp['view_img']					='['.$num.']   <a href="'.base_url().'manage_branch/branch_view/'.$P['pkid'].'">View</a>';
				$tmp['pkid']							=$P['pkid'];
				$item[] = $tmp;
			}
			$num_row = $config['total_rows'];
			$pagelink  = $this->pagination->create_links();
			return array($item,$num_row,$pagelink,$config['total_rows']);
		}
		
	}
?>